package com.hitqz.robot.biz.schedule;

import cn.hutool.extra.spring.SpringUtil;
import com.google.common.cache.Cache;
import com.hitqz.robot.api.common.entity.Robot;
import com.hitqz.robot.biz.service.RobotService;
import com.hitqz.robot.driver.parent.RobotDriverService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 调度上线的情况下，一直抢占机器人控制权， 启动默认为调度上线
 * @author xupkun
 * @date 2024/12/9
 */
@Component
@RequiredArgsConstructor
@Slf4j
public class RodRobotControllerSchedule {

    private final RobotService robotService;

    private final RobotDriverService robotDriverService;

    @Scheduled(fixedRate = 500)
    public void rodRobotController() {
        Robot robot = robotService.getDefaultRobot();
        if (robot.getDispatch() ==1) {
            // 接收调度的命令
            Cache<String,Boolean> logicOnline = SpringUtil.getBean("logicOnline");
            if (logicOnline.getIfPresent(robot.getRobotSn()) != null && logicOnline.getIfPresent(robot.getRobotSn())) {
                //robotDriverService.executeOtherCommand(RobotOtherCommandEnum.,null)
            }
        }
    }





}
